package com.czhouse.controller;

import com.czhouse.mapper.UserMapper;
import com.czhouse.pojo.User;
import com.czhouse.service.UserService;
import com.czhouse.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("addUser")
    public SysResult addUser(@RequestBody User user){
        System.out.println(user);
        if (!userService.addUser(user)){
            return SysResult.fail();
        }
        return SysResult.success();
    }
    @PostMapping("login")
    public SysResult login(@RequestBody User user){
        String token = userService.login(user);
        if (token==null){
            return SysResult.fail();
        }
        return SysResult.success(token);
    }
}
